import Api from '../../utils/http/api'
import common_utils from "../../utils/common_utils";
import time_utils from "../../utils/time_utils";

const app = getApp()

let navigationBar;

Page({
  data: {
    navigationBarHeightRpx: app.globalData.navigationBarHeightRpx, //状态栏高度
    loginFlag: app.globalData.loginFlag,//是否登录的标志
    orderConfig: [{//我的订单 数据源
        title: "待付款",
        icon: "/img/my/my_unpaid.png"
      },
      {
        title: "待发货",
        icon: "/img/my/my_unreceived.png"
      },
      {
        title: "待收货",
        icon: "/img/my/my_unshipped.png"
      },
      {
        title: "已完成",
        icon: "/img/my/my_uncheck.png"
      },
    ],
    moreConfig: [{//服务与工具 数据源
      title: "设置",
      icon: "/img/my/my_setting.png"
    }],

  },

  //------------ 生命周期 ------------
  onShow(options) {
    this.setData({
      loginFlag: getApp().globalData.loginFlag
    })
    if (!getApp().globalData.loginFlag) {//如果没登录，直接去登录界面
      wx.navigateTo({
        url: `/pages/login/login`
      })
      return
    }
    this.getUserInfo()//获取客户的信息
    navigationBar = this.selectComponent("#navigationBar")
  },
//页面滚动监听
  onPageScroll: function (e) {
    navigationBar.setOpacity(e.scrollTop, 100);
  },
  //去登录按钮
  onLogin() {
    if (!getApp().globalData.loginFlag) {
      wx.navigateTo({
        url: `/pages/login/login`
      })
    }
  },
  // 我的订单-查看全部
  onOrderTap() {
    if (!getApp().globalData.loginFlag) {
      wx.navigateTo({
        url: `/pages/login/login`
      })
      return
    }
    wx.navigateTo({
      url: '/package_shop/pages/order-list/order-list?status=0',
    })

  },
  // 我的订单点击
  onOrderBtnItem(e) {
    let index = e.detail.index
    console.log(e)

    var status = 0
    if (!getApp().globalData.loginFlag) {
      wx.navigateTo({
        url: `/pages/login/login`
      })
      return
    }
    if (index == 0) {//待付款
      status = 1
    } else if (index == 1) {//待发货
      status = 3
    } else if (index == 2) {//待收货
      status = 4
    } else if (index == 3) {//已完成
      status = 5
    }
    wx.navigateTo({
      url: `/package_shop/pages/order-list/order-list?status=${status}`,
    })
  },
  // 服务与工具点击
  onMoreBtnItem(e) {
    console.log(e)
    let index = e.detail.index
    if (!getApp().globalData.loginFlag) {
      wx.navigateTo({
        url: `/pages/login/login`
      })
      return
    }
    if (index == 0) {
      wx.navigateTo({
        url: '/package_my/pages/setting/setting',
      })
    }
  },
  //获取客户信息接口
  getUserInfo() {
    let params = {

    }
    Api.getUserInfo(params).then(res => {
      this.setData({
        userInfo: res.data
      })
    }).catch(err => console.log(err))
  },
});
